﻿CREATE PROCEDURE [dbo].[News_Select]
	@Id int =null,
	@Title NVARCHAR(255)=null , 
    @ShortDescription NVARCHAR(500)=null , 
    @Description NVARCHAR(MAX)=null , 
    @Date DATETIME =null, 
    @CreationDate DATETIME =null, 
    @CreatedBy INT =null, 
    @UpdateDate DATETIME =null, 
    @UpdateBy INT = NULL
AS

	SELECT *
	FROM [News]
	WHERE 
	(
		( @Id IS NULL OR Id = @Id ) AND 
		( @Title IS NULL OR Title LIKE @Title + '%' ) AND
		( @ShortDescription IS NULL OR ShortDescription LIKE @ShortDescription + '%' ) AND 
		( @Description IS NULL OR [Description] LIKE @Description + '%' ) AND 
		( @Date IS NULL OR cast([Date] as date) = cast(@Date as date) ) AND 
		( @CreationDate IS NULL OR cast(CreationDate as date) = cast(@CreationDate as date) ) AND 
		( @CreatedBy IS NULL OR @CreatedBy = CreatedBy ) AND 
		( @UpdateDate IS NULL OR cast(UpdateDate as date) = cast(@UpdateDate as date) ) AND 
		( @UpdateBy IS NULL OR UpdateBy = @UpdateBy )
	)
	